<template>
  <div>

    <div class="maincss">
      <el-row>
        <el-card class="">
<!--          <searchBox title='检验记录' :btn='btn' @func='showBtn'/>-->
          <el-row class="searchbox">
            <el-col span="1"> 检验规则 </el-col>
            <el-col span="3">
              <el-input
                placeholder="检验记录编号"
                v-model="queryParams.detectionNo"
              >
              </el-input>
            </el-col>
            <el-col span="3">
              <el-input
                placeholder="仪器编号"
                v-model="queryParams.instrumentNo"
              >
              </el-input>
            </el-col>
            <el-col span="4">
              <el-tree
                :data="deptOptions"
                :props="defaultProps"
                :expand-on-click-node="false"
                :filter-node-method="filterNode"
                ref="tree"
                :default-expand-all="false"
                @node-click="handleNodeClick"
              />
            </el-col>
            <el-col span="2">
                <el-select v-model="queryParams.status" placeholder="请选择检验状态">
                  <el-option
                    v-for="item in statusList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
            </el-col>
            <el-col span="3">
              <el-date-picker
                v-model="queryParams.detectionTime"
                type="datetime"
                placeholder="选择检验时间"
              >
              </el-date-picker>
            </el-col>
            <el-col span="1">
              <el-button @click="handleLoadAndQuery" type="primary">查询</el-button>
            </el-col>
<!--            <el-col span="1">-->
<!--              <el-button @click="handleLoadAndQuery" type="primary">刷新</el-button>-->
<!--            </el-col>-->
            <el-col span="2">
              <el-button @click="handleOpenAdd" type="primary">新增</el-button>
            </el-col>
          </el-row>
          <el-card class="gray-card no-border no-margin-top" shadow="never">
            <el-table
              v-loading="loading"
              :data="checkList"
              style="width: 100%;"
            >
              <el-table-column label="检验记录编号" align="center" prop="detectionNo" :show-overflow-tooltip="true"/>
              <el-table-column label="仪器编号" align="center" prop="instrumentNo" :show-overflow-tooltip="true"/>
              <el-table-column label="患者姓名" align="center" prop="patientName" :show-overflow-tooltip="true"/>
              <el-table-column label="性别" align="center" prop="gender" :show-overflow-tooltip="true"/>
              <el-table-column label="年龄" align="center" prop="age" :show-overflow-tooltip="true"/>
              <el-table-column label="检验项目" align="center" prop="projectName" :show-overflow-tooltip="true"/>
              <el-table-column label="检验时间" align="center" prop="detectionTime" :show-overflow-tooltip="true"/>
              <el-table-column label="检验结果" align="center" prop="diagnostic" :show-overflow-tooltip="true"/>
              <el-table-column label="检验科室" align="center" prop="deptName" :show-overflow-tooltip="true"/>
              <el-table-column label="检验者" align="center" prop="inspector" :show-overflow-tooltip="true"/>
              <el-table-column label="检验状态" align="center" prop="status" :show-overflow-tooltip="true">
                <template slot-scope="scope">
                  <span v-if="scope.row.status == 0">检验中</span>
                  <span v-if="scope.row.status == 1">检验完毕</span>
                </template>
              </el-table-column>
              <el-table-column label="报告生成时间" align="center" prop="reportTime" :show-overflow-tooltip="true"/>
              <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                  <el-button
                    size="mini"
                    type="text"
                    @click="handleOpenDetail(scope.row)"
                    v-hasPermi="['monitor:online:forceLogout']"
                  >详情
                  </el-button>
                  <el-button
                    size="mini"
                    type="text"
                    @click="handleEdit(scope.row)"
                    v-hasPermi="['monitor:online:forceLogout']"
                  >编辑
                  </el-button>
<!--                  <el-button-->
<!--                    size="mini"-->
<!--                    type="text"-->
<!--                    @click="handleSend(scope.row)"-->
<!--                    v-hasPermi="['monitor:online:forceLogout']"-->
<!--                  >发送-->
<!--                  </el-button>-->
                  <el-button
                    size="mini"
                    type="text"
                    @click="handleDownload(scope.row)"
                    v-hasPermi="['monitor:online:forceLogout']"
                  >下载
                  </el-button>
                  <el-button
                    size="mini"
                    type="text"
                    @click="handlePrint(scope.row)"
                    v-hasPermi="['monitor:online:forceLogout']"
                  >打印
                  </el-button>
                  <el-button
                    size="mini"
                    type="text"
                    @click="handleProduceReport(scope.row)"
                    v-hasPermi="['monitor:online:forceLogout']"
                  >生成报告
                  </el-button>
                </template>
              </el-table-column>
            </el-table>
          </el-card>

          <pagination v-show="total>0" :total="total"
                      :page.sync="queryParams.pageNum"
                      :limit.sync="queryParams.pageSize"
                      @pagination="handleLoadAndQuery"/>


        </el-card>
      </el-row>
      <el-drawer class="no-head"
                 :visible.sync="detailShow"
                 size='65%'
      >
        <checkDetail  @close="handleCloseDetail"
                      ref="detailRef"/>
      </el-drawer>

      <el-drawer
        :title="addTitle"
        :visible.sync="addShow"
        size='65%'
      >
        <addexamine @close="handleCloseAdd"
                    ref="AddRef"/>
      </el-drawer>
    </div>
  </div>
</template>

<script>
import checkDetail from './checkDetail.vue'
import addexamine from './addexamine.vue'
import {listDetectionResult, getDetectionResult, updateDetectionResult} from "@/api/business/detectionResult"
import { treeselect } from "@/api/system/dept";
import {parseTime} from '@/utils/ruoyi'

export default {
  name: "eaxmine",
  components: {
    checkDetail,
    addexamine
  },
  data() {
    return {
      btn: {
        add: true,
        reg: false,
        down: false,
        export: false,
        imp: false,
        ref: true,
        search: true
      },
      addShow: false,
      detailShow: false,
      checkList: [],
      loading: false,
      total: 0,
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        deptId: '',
        detectionNo: '',
        instrumentNo: '',
        status: '',
        detectionTime: ''
      },
      statusList: [
        {
          label: '全部',
          value: ''
        },
        {
          label: '检验中',
          value: 0
        },
        {
          label: '检验完毕',
          value: 1
        }
      ],
      addTitle: '新增检验记录',
      // 部门树选项
      deptOptions: undefined,
      defaultProps: {
        children: "children",
        label: "label"
      }
    };
  },
  watch: {},
  created() {
    this.getTreeselect();
    this.$nextTick(() => {
      this.handleLoadAndQuery()
    })
  },
  methods: {
    handleOpenDetail(row) {
      this.detailShow = true
      this.$nextTick(() => {
        this.$refs.detailRef.handleData(row)
      })
    },
    showBtn(data) {
      if (data == 'add') {
        this.handleOpenAdd()
      } else if (data === 'search' || data == 'refresh') {
        this.handleLoadAndQuery()
      }
    },
    handleOpenAdd() {
      this.addShow = true;
      this.addTitle = '新增检验记录'
    },
    handleLoadAndQuery() {
      if (this.queryParams.detectionTime) {
        this.queryParams.detectionTime = parseTime(this.queryParams.detectionTime)
      } else {
        this.queryParams.detectionTime = ''
      }
      this.checkList = []
      this.loading = true;
      listDetectionResult(this.queryParams).then((res) => {
        this.loading = false;
        this.total = res.total;
        this.checkList = res.rows;
      })
        .catch(() => {
          this.loading = false;
        })
    },
    // 关闭新增页面
    handleCloseAdd() {
      this.addShow = false;
      this.handleLoadAndQuery()
    },
    handleCloseDetail() {
      this.detailShow = false;
      this.handleLoadAndQuery()
    },
    // 修改数据
    handleEdit(row) {
      this.addShow = true;
      this.addTitle = '修改检验记录'
      this.$nextTick(() => {
        this.$refs.AddRef.handleData(row)
      })
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    // 节点单击事件
    handleNodeClick(data) {
      this.queryParams.deptId = data.id;
      this.getList();
    },
    /** 查询部门下拉树结构 */
    getTreeselect() {
      treeselect().then(response => {
        this.deptOptions = response.data;
      });
    },
    // 发送
    handleSend(row) {

    },
    // 下载
    handleDownload(row) {

    },
    // 打印
    handlePrint(row) {

    },
    // 生成报告
    handleProduceReport(row) {

    }
  }
};
</script>
